#!/usr/bin/env python
# -*- coding: utf-8 -*-

##################################################################################
#Version Histroy
#Ver00 : Initial Version   2007/08/12  RogerZheng

##################################################################################
#   How to Use
#1. Datalog File Name format for J750: TesterName-TestNum-Num-.txt
#   Datalog File Name format for MT9000: TesterName-TestNum-Num-PatternName-.txt
#2. All datalog file need to be same directory
#3. Generator a Excel file: Shmoo.xls
#4. if the file: Shmoo.xls is exist, it will mv it to Shmoo.xls_org

import os
import glob
import shutil
import re
import pyExcelerator as PyXLS

TitleFont = PyXLS.Font()
TitleFont.height = 15*0x12
TitleFont.name = 'MS Mincho'
TitleFont.bold = True
TitleFont.underline = PyXLS.Font.UNDERLINE_SINGLE
#TitleFont.colour_index = 4

TitleStyle = PyXLS.XFStyle()
TitleStyle.font = TitleFont

TesterFont = PyXLS.Font()
TesterFont.height = 15*0x12
TesterFont.name = 'MS Mincho'
TesterFont.bold = True
#TesterFont.underline = PyXLS.Font.UNDERLINE_SINGLE
#TitleFont.colour_index = 4

Font = PyXLS.Font()
Font.name = 'MS Mincho'
Font.bold = True
Font.height = 8*0x12

ShmooFont = PyXLS.Font()
ShmooFont.name = 'MS Mincho'
ShmooFont.bold = False
ShmooFont.height = 12*0x12

ShmooLeftBord = PyXLS.Borders()
ShmooLeftBord.left = 0x01

ShmooRightBord = PyXLS.Borders()
ShmooRightBord.right = 0x01

ShmooTopBord = PyXLS.Borders()
ShmooTopBord.top = 0x01

ShmooBottomBord = PyXLS.Borders()
ShmooBottomBord.bottom = 0x01

ShmooNoBoarderBord = PyXLS.Borders()
ShmooNoBoarderBord.left = 0x00
ShmooNoBoarderBord.right = 0x00
ShmooNoBoarderBord.top = 0x00
ShmooNoBoarderBord.bottom = 0x00

ShmooLeftTopBord = PyXLS.Borders()
ShmooLeftTopBord.left = 0x01
ShmooLeftTopBord.top = 0x01

ShmooLeftBottomBord = PyXLS.Borders()
ShmooLeftBottomBord.left = 0x01
ShmooLeftBottomBord.bottom = 0x01

ShmooRightTopBord = PyXLS.Borders()
ShmooRightTopBord.right = 0x01
ShmooRightTopBord.top = 0x01

ShmooRightBottomBord = PyXLS.Borders()
ShmooRightBottomBord.right = 0x01
ShmooRightBottomBord.bottom = 0x01


Bord = PyXLS.Borders()
Bord.left = 0x01
Bord.right = 0x01
Bord.top = 0x01
Bord.bottom = 0x01

Alg = PyXLS.Alignment()
Alg.horz = PyXLS.Alignment.HORZ_LEFT
Alg.vert = PyXLS.Alignment.VERT_CENTER

#pattern_fore_colour:
#0x00: black; 0x01: white; 0x02: red; 0x03: green; 0x04: blue; 0x05: yellow; 0x06: pink; 0x07: turquoise;

TesterPat = PyXLS.Pattern()
TesterPat.pattern = PyXLS.Pattern.SOLID_PATTERN
TesterPat.pattern_fore_colour = 0x16

TestValuePat = PyXLS.Pattern()
TestValuePat.pattern = PyXLS.Pattern.SOLID_PATTERN
TestValuePat.pattern_fore_colour = 0x01


TesterSty = PyXLS.XFStyle()
TesterSty.font =TesterFont
TesterSty.alignment = Alg
#TesterSty.pattern = TesterPat
#TesterSty.borders = Bord

TestValueSty = PyXLS.XFStyle()
TestValueSty.font = Font
TestValueSty.alignment = Alg
TestValueSty.pattern = TestValuePat
TestValueSty.borders = Bord

ShmooLeftSty = PyXLS.XFStyle()
ShmooLeftSty.font = ShmooFont
ShmooLeftSty.alignment = Alg
ShmooLeftSty.pattern = TestValuePat
ShmooLeftSty.borders = ShmooLeftBord

ShmooRightSty = PyXLS.XFStyle()
ShmooRightSty.font = ShmooFont
ShmooRightSty.alignment = Alg
ShmooRightSty.pattern = TestValuePat
ShmooRightSty.borders = ShmooRightBord

ShmooTopSty = PyXLS.XFStyle()
ShmooTopSty.font = ShmooFont
ShmooTopSty.alignment = Alg
ShmooTopSty.pattern = TestValuePat
ShmooTopSty.borders = ShmooTopBord

ShmooBottomSty = PyXLS.XFStyle()
ShmooBottomSty.font = ShmooFont
ShmooBottomSty.alignment = Alg
ShmooBottomSty.pattern = TestValuePat
ShmooBottomSty.borders = ShmooBottomBord

ShmooNoBoarderSty = PyXLS.XFStyle()
ShmooNoBoarderSty.font = ShmooFont
ShmooNoBoarderSty.alignment = Alg
ShmooNoBoarderSty.pattern = TestValuePat
ShmooNoBoarderSty.borders = ShmooNoBoarderBord

ShmooLeftTopSty = PyXLS.XFStyle()
ShmooLeftTopSty.font = ShmooFont
ShmooLeftTopSty.alignment = Alg
ShmooLeftTopSty.pattern = TestValuePat
ShmooLeftTopSty.borders = ShmooLeftTopBord

ShmooLeftBottomSty = PyXLS.XFStyle()
ShmooLeftBottomSty.font = ShmooFont
ShmooLeftBottomSty.alignment = Alg
ShmooLeftBottomSty.pattern = TestValuePat
ShmooLeftBottomSty.borders = ShmooLeftBottomBord

ShmooRightTopSty = PyXLS.XFStyle()
ShmooRightTopSty.font = ShmooFont
ShmooRightTopSty.alignment = Alg
ShmooRightTopSty.pattern = TestValuePat
ShmooRightTopSty.borders = ShmooRightTopBord

ShmooRightBottomSty = PyXLS.XFStyle()
ShmooRightBottomSty.font = ShmooFont
ShmooRightBottomSty.alignment = Alg
ShmooRightBottomSty.pattern = TestValuePat
ShmooRightBottomSty.borders = ShmooRightBottomBord


def J750AsciiShmoo2Array(DataFile,DummyLine,TotalSampleCount,ShmooPlot,TestInstanceName,PatternName,ProgramName):
    
    TempGroups=re.search(r"(\w+)(-)(\d+)(-)(\d+)(.*)",os.path.basename(DataFile)).groups()
    TempTesterNo=TempGroups[2].strip()
    SampleCount=TempGroups[4].strip()
    
    if os.path.isfile(DataFile):
        OpenFileFH=open(DataFile)
    else:
        print "Error! Not Found File: ",DataFile
    
    #StartLabel for Shmoo test log:****  Period vs Vps Shmoo Plot  ****
    CompliedStartLabel=re.compile(r"(\*\*\*\*\s+\w+.*Shmoo Plot\s+\*\*\*\*)")
    
    #EndLabel for Shmoo Test log: P=PASS   +-!.=FAIL   ?=ERROR
    CompliedEndLabel =re.compile(r"(\s*P=PASS\s+\+-!\.=FAIL\s+\?=ERROR\s*)")
    
    #InstanceName :     Test Instance : RAM1  Shmoo
    CompliedInstanceName=re.compile(r"(\s+Test Instance\s+:)(.*)")
    
    #PatternName :     Pattern       : RAM
    CompliedPatternName=re.compile(r"(\s+Pattern\s+:)(\s+\w+\s+)(.*)")
    
    #TestProgramName:    Program       : f5f2118400d_rev16_20070802_TDR_WithASCIIShmo.xls
    CompliedProgramName=re.compile(r"(\s+Program\s+:)(.*)")
    
    #Function Test : 102     0    PASS     CPU1                      p5f21194cpua_0
    CompliedFunc=re.compile(r"\s*\d+\s+\d+\s+\w+\s+\w+\s+\w+")
    
    Lines=OpenFileFH.readlines()    
    FlagShmooPlotStart=False
    FlagContinueSite=False
    FlagEndLabel=False
    FlagSiteData=False    
    SampleNo =0
    TempSite={}
        
    for Line in Lines:
        #Find Label or Varible
        if CompliedStartLabel.search(Line):
            FlagShmooPlotStart=True            
        elif CompliedEndLabel.search(Line):
            if FlagShmooPlotStart:
                FlagContinueSite=True
                Count=0
        elif CompliedInstanceName.search(Line):
            TempTestInstanceName=CompliedInstanceName.search(Line).groups()[1].strip()
        elif CompliedPatternName.search(Line):            
            TempPatternName=CompliedPatternName.search(Line).groups()[1].strip()
        elif CompliedProgramName.search(Line):
            TempProgramName=CompliedProgramName.search(Line).groups()[1].strip()
        elif CompliedFunc.search(Line):
            FlagShmooPlotStart=False
            FlagContinueSite=False
            
        #SiteNum=""
        if FlagShmooPlotStart:
            Count=Count+1
            if FlagContinueSite:
                if re.search(r"\s+Site\s+:\s+\d+",Line):
                    SiteNum=re.search(r"(\s+Site\s+:)(\s+\d+)",Line).groups()[1].strip()                
                
                if FlagSiteData and not CompliedEndLabel.search(Line) and not re.search("^\n$",Line) and Count > 4:         
                    if TempSite.has_key(SiteNum):
                        SampleNo=TempSite[SiteNum]
                    else:
                        TempSite[SiteNum]=SampleCount
                        SampleNo=SampleCount  
                        if type(SampleCount)==type(1):
                            SampleCount=SampleCount+1
                        else:
                            SampleCount=eval(SampleCount)+1
                    TempKey="".join(("Tester",TempTesterNo,"_Sample",str(SampleNo),"_",TempPatternName))                    
                    
                    if ShmooPlot.has_key(TempKey):
                        ShmooPlot[TempKey]="".join((ShmooPlot[TempKey],Line))
                    else:
                        ShmooPlot[TempKey]=Line
                        TestInstanceName[TempKey]=TempTestInstanceName
                        PatternName[TempKey]=TempPatternName
                        ProgramName[TempKey]=TempProgramName
                        
                    if TotalSampleCount < SampleCount:
                        TotalSampleCount=SampleCount
            else:                
                if Count >= DummyLine:
                    FlagSiteData=True
                else:
                    FlagSiteData=False
                if re.search(r"\s+Site\s+:\s+\d+",Line):
                    SiteNum=re.search(r"(\s+Site\s+:)(\s+\d+)",Line).groups()[1].strip()                
                
                if FlagSiteData and not CompliedEndLabel.search(Line) and not re.search("^\n$",Line):                 
                    if TempSite.has_key(SiteNum):
                        SampleNo=TempSite[SiteNum]
                    else:
                        TempSite[SiteNum]=SampleCount
                        SampleNo=SampleCount  
                        if type(SampleCount)==type(1):
                            SampleCount=SampleCount+1
                        else:
                            SampleCount=eval(SampleCount)+1
                    TempKey="".join(("Tester",TempTesterNo,"_Sample",str(SampleNo),"_",TempPatternName))
                    if ShmooPlot.has_key(TempKey):
                        ShmooPlot[TempKey]="".join((ShmooPlot[TempKey],Line))
                    else:
                        ShmooPlot[TempKey]=Line
                        TestInstanceName[TempKey]=TempTestInstanceName
                        PatternName[TempKey]=TempPatternName
                        ProgramName[TempKey]=TempProgramName
                        
                    if TotalSampleCount < SampleCount:
                        TotalSampleCount=SampleCount
        else:
            Count=0 
    return(TotalSampleCount,ShmooPlot,TestInstanceName,PatternName,ProgramName)
       
def MTAsciiShmoo2Array(DataFile,DummyLine,TotalSampleCount,ShmooPlot,TestInstanceName,PatternName,ProgramName):
    
    TempGroups=re.search(r"(\w+)(-)(\d+)(-)(\d+)(-)(\w+)(-)(.*)",os.path.basename(DataFile)).groups()
    TempTesterNo=TempGroups[2].strip()
    SampleCount=eval(TempGroups[4].strip())-1
    TempPatternName=TempGroups[6].strip()
    
    if os.path.isfile(DataFile):
        OpenFileFH=open(DataFile)
    else:
        print "Error! Not Found File: ",DataFile
    
    #StartLabel for Shmoo test log:****  Period vs Vps Shmoo Plot  ****
    CompliedStartLabel=re.compile(r"(\*\*\s*DISPLAY\s*\*\*)")
    
    #EndLabel for Shmoo Test log: P=PASS   +-!.=FAIL   ?=ERROR
    CompliedEndLabel =re.compile(r"(\s*Z COMMENT  )")
        
    Lines=OpenFileFH.readlines()    
    FlagShmooPlotStart=False
    FlagContinueSite=False
    FlagEndLabel=False
    FlagSiteData=False    
    SampleNo =0
        
    for Line in Lines:
        #Find Label or Varible
        if CompliedStartLabel.search(Line):
            FlagShmooPlotStart=True
            SampleCount=SampleCount+1
        elif CompliedEndLabel.search(Line):
            FlagShmooPlotStart=False
        
        #SiteNum=""
        if FlagShmooPlotStart:
            SampleNo=SampleCount
            Count=Count+1                           
            if Count >= DummyLine:
                FlagSiteData=True
            else:
                FlagSiteData=False
            
            if FlagSiteData and not CompliedEndLabel.search(Line) and not re.search("^\n$",Line):                 
                TempKey="".join(("Tester",TempTesterNo,"_Sample",str(SampleNo),"_",TempPatternName))
                if ShmooPlot.has_key(TempKey):
                    ShmooPlot[TempKey]="".join((ShmooPlot[TempKey],Line))
                else:
                    ShmooPlot[TempKey]=Line
                    PatternName[TempKey]=TempPatternName
                        
                if TotalSampleCount < SampleCount:
                    TotalSampleCount=SampleCount
        else:
            Count=0 
    return(TotalSampleCount,ShmooPlot,TestInstanceName,PatternName,ProgramName)
       
def ShmooPlotRaw2Excel(HeadLine,BottomLine,TotalSampleCount,JTesterNum,JShmooPlot,JPatternName,MTesterNum,MShmooPlot,MPatternName):
    
    TesterNum=JTesterNum
    if JTesterNum < MTesterNum:
        TesterNum = MTesterNum
    WorkBkStCount=0
    SameSite=False
    WritedSample=[]
    
    for SampleNo in range(1,TotalSampleCount+1):
        SameSite=True
        if MTesterNum>0:
            MStartColum=InitCellColum
        else:
            MStartColum=0
        JStartColum=MStartColum+(MTesterNum)*InitColumInterval        
        MTesterNameLocation=InitTesterNameLocation
        JTesterNameLocation=MTesterNameLocation+(MTesterNum-1)*InitColumInterval
        WritedMTester=[]
        WritedJTester=[]
        for TesterNo  in range(TesterNum+1):
        #for TesterNo  in range(3):
            JStartRow=InitCellRow
            MStartRow=InitCellRow
            TesterId=""
            SameMTester=True
            SameJTester=True
            
            for TempPatternName in MPatternNameOrder:
                FlagRowInteravl=False
                SampleId=""
                TempKey=""
                TempKey="".join(("Tester",str(TesterNo),"_Sample",str(SampleNo),"_",TempPatternName))
                if MShmooPlot.has_key(TempKey):
                    SampleId="".join(("S",str(SampleNo)))                  
                    if SameSite:
                        SameSite = False
                    if SampleId in WritedSample:
                        pass
                    else:
                        WorkSt = WorkBk.add_sheet("".join(("S",str(SampleNo))))
                        WorkSt.write(1,1,"".join(("Sample",str(SampleNo))),TitleStyle)
                        WritedSample.append(SampleId)
                        WorkBkStCount=WorkBkStCount+1
                        
                    TesterId="".join(("Tester:",str(TesterNo)))
                    if SameMTester:
                        SameMTester = False
                    if TesterId in WritedMTester:
                        pass
                    else:
                        TesterId="".join(("Tester:",str(TesterNo)))
                        WorkSt.write(1,MTesterNameLocation,"".join(("Tester:",str(TesterNo))),TitleStyle)
                        WritedMTester.append(TesterId)
                        MTesterNameLocation=MTesterNameLocation+InitColumInterval
                        
                    #Print Pattern Name and Tester Type                    
                    WorkSt.write(MStartRow,MStartColum+1,TempPatternName,TitleStyle)
                    WorkSt.write(MStartRow,MStartColum+5,"MT9000",TesterSty)
                    MStartRow=MStartRow+2
                    
                    #Print HeadLine
                    WorkSt.write(MStartRow,MStartColum,HeadLine,ShmooLeftTopSty)
                    for Index in range(1,InitColumInterval-2):
                        WorkSt.write(MStartRow,MStartColum+Index,"",ShmooTopSty)
                    WorkSt.write(MStartRow,MStartColum+InitColumInterval-2,"",ShmooRightTopSty)
                    MStartRow=MStartRow+1
                    
                    #Print Dummy Text
                    for Line in re.split(r"\n",MTDummyText.rstrip()):
                        WorkSt.write(MStartRow,MStartColum,Line,ShmooLeftSty)
                        for Index in range(1,InitColumInterval-2):
                            WorkSt.write(MStartRow,MStartColum+Index,"",ShmooNoBoarderSty)
                        WorkSt.write(MStartRow,MStartColum+InitColumInterval-2,"",ShmooRightSty)
                        MStartRow=MStartRow+1
                        
                    #Print ASCII Shmoo Plot
                    for Line in re.split(r"\n",MShmooPlot[TempKey].rstrip()):
                        WorkSt.write(MStartRow,MStartColum,Line,ShmooLeftSty)
                        for Index in range(1,InitColumInterval-2):
                            WorkSt.write(MStartRow,MStartColum+Index,"",ShmooNoBoarderSty)
                        WorkSt.write(MStartRow,MStartColum+InitColumInterval-2,"",ShmooRightSty)
                        MStartRow=MStartRow+1
                    
                    #Print BottomLine
                    WorkSt.write(MStartRow,MStartColum,BottomLine,ShmooLeftBottomSty)
                    for Index in range(1,InitColumInterval-2):
                        WorkSt.write(MStartRow,MStartColum+Index,"",ShmooBottomSty)
                    WorkSt.write(MStartRow,MStartColum+InitColumInterval-2,"",ShmooRightBottomSty)
                    MStartRow=MStartRow+1
                    
                    #if FlagRowInteravl:
                    MStartRow=MStartRow+InitRowInterval
            if SameMTester:
                pass
            else:
                MStartColum=MStartColum+InitColumInterval
            for TempPatternName in JPatternNameOrder:
                FlagRowInteravl=False
                SampleId=""
                TempKey=""
                TempKey="".join(("Tester",str(TesterNo),"_Sample",str(SampleNo),"_",TempPatternName))
                if JShmooPlot.has_key(TempKey):
                    SampleId="".join(("S",str(SampleNo)))                  
                    if SameSite:
                        SameSite = False
                    if SampleId in WritedSample:
                        pass
                    else:
                        WorkSt = WorkBk.add_sheet("".join(("S",str(SampleNo))))
                        WorkSt.write(1,1,"".join(("Sample",str(SampleNo))),TitleStyle)
                        WritedSample.append(SampleId)
                        WorkBkStCount=WorkBkStCount+1
                    TesterId="".join(("Tester:",str(TesterNo)))
                    if SameMTester:
                        SameMTester = False
                    if TesterId in WritedMTester:
                        pass
                    else:
                        TesterId="".join(("Tester:",str(TesterNo)))
                        WorkSt.write(1,MTesterNameLocation,"".join(("Tester:",str(TesterNo))),TitleStyle)
                        WritedMTester.append(TesterId)
                        MTesterNameLocation=MTesterNameLocation+InitColumInterval
                    
                    #Print Pattern Name and Tester Type
                    WorkSt.write(JStartRow,JStartColum+1,TempPatternName,TitleStyle)
                    WorkSt.write(JStartRow,JStartColum+5,"J750",TesterSty)
                    JStartRow=JStartRow+2
                    
                    #Print HeadLine
                    WorkSt.write(JStartRow,JStartColum,HeadLine,ShmooLeftTopSty)
                    for Index in range(1,InitColumInterval-2):
                        WorkSt.write(JStartRow,JStartColum+Index,"",ShmooTopSty)
                    WorkSt.write(JStartRow,JStartColum+InitColumInterval-2,"",ShmooRightTopSty)
                    JStartRow=JStartRow+1
                    
                    #Print ASCII Shmoo Plot
                    for Line in re.split(r"\n",JDummyText.rstrip()):
                        WorkSt.write(JStartRow,JStartColum,Line,ShmooLeftSty)
                        for Index in range(1,InitColumInterval-2):
                            WorkSt.write(JStartRow,JStartColum+Index,"",ShmooNoBoarderSty)
                        WorkSt.write(JStartRow,JStartColum+InitColumInterval-2,"",ShmooRightSty)
                        JStartRow=JStartRow+1
                        
                    #Print ASCII Shmoo Plot
                    for Line in re.split(r"\n",JShmooPlot[TempKey].rstrip()):
                        WorkSt.write(JStartRow,JStartColum,Line,ShmooLeftSty)
                        for Index in range(1,InitColumInterval-2):
                            WorkSt.write(JStartRow,JStartColum+Index,"",ShmooNoBoarderSty)
                        WorkSt.write(JStartRow,JStartColum+InitColumInterval-2,"",ShmooRightSty)
                        JStartRow=JStartRow+1
                        #FlagInteravl=True
                    
                    #Print BottomLine
                    WorkSt.write(JStartRow,JStartColum,BottomLine,ShmooLeftBottomSty)
                    for Index in range(1,InitColumInterval-2):
                        WorkSt.write(JStartRow,JStartColum+Index,"",ShmooBottomSty)
                    WorkSt.write(JStartRow,JStartColum+InitColumInterval-2,"",ShmooRightBottomSty)
                    JStartRow=JStartRow+1
                    
                    #if FlagRowInteravl:
                    JStartRow=JStartRow+InitRowInterval
                        
            if SameJTester:
                pass
            else:
                JStartColum=JStartColum+InitColumInterval
            
    (TotalSampleCount,JTesterNum,JShmooPlot,JPatternName,MTesterNum,MShmooPlot,JpatternName)=(0,0,{},[],0,{},[])
    #(MSampleCount,MTotalTestItemNum,MTotalTestNum,MTotalSW,MTestValue,MTesterNo,MTestResult,MTestUnit,MTestLowLmt,MTestLowUnit,MTestHighLmt,MTestHighUnit)=(0,0,0,0,{},{},{},{},{},{},{},{})
    TotalSampleCount = 0
    TotalSW = 0
    TotalTestNum = 0
    TotalTestItemNum = 0
    JTestValue={}
    MTestValue={}
    return WorkBkStCount

if __name__ == "__main__":
    
    CurrentPath = os.getcwd()
    ##########################################################
    #User Edit Area 
    #
    WorkBkName= os.path.join(CurrentPath,"AsciiShmoo.xls")
    WarningFile=os.path.join(CurrentPath,"AsciiShmoo_Warning.txt")
    JPatternNameOrder=["p5f21194cpua_0","p5f21194porb_0","RAM","CLOCK","ADFUNC","TIMERX","TIMERZ","TIMERC","ICE"]
    HeadLine="Voltage    (V)"
    BottomLine="VCC                                          TRATE"
    JDummyLine=13
    JDummyText=""
    MTDummyText=" \n          30.0      50.0      70.0      90.0      110.0     130.0\n            +----+----+----+----+----+----+----+----+----+----+"
    MDummyLine=5
    MPatternNameOrder=["CPU","PORT","CLOCK","RAM","TIMERZ","TIMERX","TIMERC","ADFUN","ICE"]
    
    #User Edit Area End
    
    if os.path.isfile(WarningFile):
        os.unlink(WarningFile)
        
    SampleSize=8
    TesterSize=16
    InitRowInterval=1
    InitColumInterval=10
    InitCellRow=3
    InitCellColum=1
    InitTesterNameLocation=8
    
    if os.path.isfile(WorkBkName):
        try:
            shutil.move(WorkBkName,"".join((WorkBkName,"_org")))
        except WindowsError:
            print "Please Close the file: \n", WorkBkName," ! \n And Re-run the program!"
            os.sys.exit()
    
    WorkBk=PyXLS.Workbook()
    Files=sorted(glob.glob("*"))
        
    (JSampleCount,JShmooPlot,JTestInstanceName,JPatternName,JProgramName)=(0,{},{},{},{})
    (MSampleCount,MShmooPlot,MTestInstanceName,MPatternName,MProgramName)=(0,{},{},{},{})
    
    TotalSampleCount = 0    
    TotalTestNum = 0
    TotalTestItemNum = 0
    JTempTester=0
    MTempTester=0
    WorkBkStCount=0
    
    for Index in range(TesterSize+1):
        JTotalSampleCount=0
        MTotalSampleCount=0
        for File in Files:        
                
            if re.search(r"(^J750-)(\d+)(-)(\d+)(.*)",File,re.I):
                if re.search(r"(J750-)(\d+)(-)(\d+)(.*)",File,re.I).group(2).strip()==str(Index+1):
                    (JTotalSampleCount,JShmooPlot,JTestInstanceName,JPatternName,JProgramName) =J750AsciiShmoo2Array(File,JDummyLine,JTotalSampleCount,JShmooPlot,JTestInstanceName,JPatternName,JProgramName)
                    if JTempTester < eval(re.search(r"(J750-)(\d+)(-)(\d+)(.*)",File,re.I).group(2).strip()):
                        JTempTester = eval(re.search(r"(J750-)(\d+)(-)(\d+)(.*)",File,re.I).group(2).strip())
            if re.search(r"(^MT-)(\d+)(-)(\d+)(-)(\w+)(-)(.*)",File,re.I):
                if re.search(r"(MT-)(\d+)(-)(\d+)(.*)",File,re.I).group(2).strip() == str(Index+1):
                    (MTotalSampleCount,MShmooPlot,MTestInstanceName,MPatternName,MProgramName) =MTAsciiShmoo2Array(File,MDummyLine,MTotalSampleCount,MShmooPlot,MTestInstanceName,MPatternName,MProgramName)
                    if MTempTester < eval(re.search(r"(MT-)(\d+)(-)(\d+)(.*)",File,re.I).group(2).strip()):
                        MTempTester = eval(re.search(r"(MT-)(\d+)(-)(\d+)(.*)",File,re.I).group(2).strip())
                    
        if TotalSampleCount < JTotalSampleCount:
            TotalSampleCount = JTotalSampleCount
        if TotalSampleCount < MTotalSampleCount:
            TotalSampleCount = MTotalSampleCount
    
    #JShmooPlot={}
    #MPatternName=[]
    if len(JShmooPlot)or len(MShmooPlot) >0:
        WorkBkStCount=ShmooPlotRaw2Excel(HeadLine,BottomLine,TotalSampleCount,JTempTester,JShmooPlot,JPatternName,MTempTester,MShmooPlot,MPatternName)
    if WorkBkStCount>0:
        WorkBk.save(WorkBkName) 
    else:
        WarningFileFH=open(WarningFile,"w")
        WarningFileFH.write("No data for shmoo was found!")
    